package com.kermitye.treenodelib

import android.content.Context
import androidx.annotation.NonNull

abstract class SimpleTreeNodeAdapter<T>(
    context: Context,
    layoutId: Int,
    @NonNull rootList: List<TreeNode<T>>
) : TreeNodeAdapter<T>(context, rootList) {
    abstract fun convert(
        adapter: TreeNodeAdapter<T>?,
        holder: BaseViewHolder,
        treeNode: TreeNode<T>
    )

    /**
     * 构造器
     *
     * @param context  上下文
     * @param rootList 树节点根列表（所有数据）
     */
    init {
        addItemViewDelegate(object : TreeNodeDelegate<T>() {

            override fun convert(holder: BaseViewHolder, treeNode: TreeNode<T>) {
                this@SimpleTreeNodeAdapter.convert(adapter, holder, treeNode)
            }

            override val layoutId: Int
                get() = layoutId

            override fun setLevelTag(): Int {
                return 0
            }
        })
    }
}